<template>
  <MenuNavigation />
  <div
    @wheel.stop="handleScroll"
    class="jy-style-height Cultural-box"
    :style="{
      background: `rgba(33, 33, 33, 1) url(${
        publicUrls + 'free/style4/publicStyle4Bg.png' + '?imageView2/3/format/webp'
      })`,
    }"
  >
    <div class="cultural-bg">
      <div class="Cultural-heard">
        <img class="backHome" @click="blankHome" :src="publicUrls + 'free/style4/backHome.png'" alt="" />
        <span class="Cultural-heard-title">文创商品</span>
        <i class="freeIcon">&#xe642;</i>
        <!-- <div class="percentage-text">
        <span v-if="list.length > 4">{{ percentage }}%</span>
      </div> -->
      </div>
      <ScrollBoxCom
        color="rgba(50, 43, 37, 1)"
        v-if="scrollheight"
        :byid="98672"
        :width="getScrollHeight"
        :scroll-src="publicUrls + 'free/style4/scrollBar.png'"
      >
        <template #solidBorderCon>
          <div class="right-scroll" ref="scrollBox" :style="list?.length <= 4 && { justifyContent: 'center' }">
            <div class="is-null" v-if="list.length === 0 && !loading">
              <img :src="publicUrls + 'free/style2/exhibitsImg.png'" alt="" />
              <span>暂无文创商品</span>
            </div>
            <!-- <div class="is-null" v-if="list.length === 0 && !loading"><span>暂无文创商品</span></div> -->
            <div class="item-parent" v-for="(item, index) in list" :key="item.id">
              <div
                class="item"
                :class="{ 'item-1': index === 0, 'item-max': index === list.length - 1 }"
                :style="{ cursor: item.url ? 'pointer' : 'not-allowed' }"
                @click="pathLink(item.url)"
              >
                <div class="item-img-box">
                  <img
                    class="item-img t-image t-image--fit-cover t-image--position-center"
                    v-if="!item.coverUrl"
                    src="http://101.34.143.36:8890/api/image/387939155165253"
                    alt=""
                  />
                  <img
                    class="item-img t-image t-image--fit-cover t-image--position-center"
                    v-else
                    :src="$filters.getLinkUrl(item.coverUrl + '?imageView2/1/w/270/h/270/format/webp')"
                    alt=""
                  />
                </div>
                <p class="item-name">{{ item.name }}</p>
                <div class="item-btm">
                  <span class="item-title3" v-if="item.price">参考价</span>
                  <span class="item-title2" v-if="item.price">￥{{ item.price }}</span>
                  <span class="item-title2 item-title4" v-else>暂无价格</span>
                </div>
              </div>
            </div>
          </div>
        </template>
        <template #solidBorderEx>
          <div class="solidBorder-child"></div>
        </template>
      </ScrollBoxCom>
      <div class="content-door">
        <i class="iconfonts">&#xe6dd;</i>
        <span>永不落幕的展览与展示平台</span>
      </div>
    </div>
  </div>
</template> 

<script lang="ts">
export default defineComponent({
  name: 'style4',
});
</script>

<script setup lang="ts">
// @ts-nocheck
import { publicUrls } from '@/utils/minxin';
import { goodsList } from '@/api/goods/goods';
import RightMenu from '../components/rightMenu.vue';
import Logo from '../components/logo.vue';
import FooterHome from '../components/footerHome.vue';
import MenuNavigation from '@/freeComponents/menuNavigation/index.vue';
import PublicTitle from '../components/PublicTitle.vue';
import { useRouter, useRoute } from 'vue-router';
import ScrollBoxCom from '../scrollBoxUp.vue';
import { ref, watch, reactive, nextTick, defineComponent } from 'vue';
import { copyrightSave, copyrightInfo } from '@/api/templates/templates';
import { useProjectStore, commonDataStore } from '@/store';
import { storeToRefs } from 'pinia';
import { computed } from 'vue';

const parmas = reactive({
  value: '',
  pageNo: 1,
  pageSize: 100,
});
const topShow = ref(false);
const scrollBox = ref(null);
const percentage = ref(0);
const list = ref([]);
const total = ref(0);
const loading = ref(false);
const store = useProjectStore();
const scrollheight = ref();
const router = useRouter();
const route = useRoute();
const Description = ref('');
const init = async () => {
  try {
    if (loading.value) {
      return;
    }
    loading.value = true;
    let res = await goodsList(localStorage.getItem('projectId'), parmas);
    total.value = res.data.total;
    list.value = list.value.concat(res.data.data);
    // list.value = [];
    loading.value = false;
  } catch {
    loading.value = false;
  }
};
init();

let viewportheight = window.innerHeight;
scrollheight.value = (viewportheight / 900) * 460;

const getScrollHeight = computed(() => {
  let heights = (window.innerHeight / 900) * 460;
  return heights;
});

const handleScroll = (event) => {
  event.preventDefault(); // 阻止默认滚动行为
  const { deltaY } = event;

  // 获取滚动内容的 DOM 元素
  const contentEl = scrollBox.value;

  // 将滚动盒子向前滚动
  contentEl.scrollLeft += deltaY;
  if (contentEl.scrollWidth > contentEl.clientWidth) {
    if (
      contentEl.scrollWidth < contentEl.scrollLeft + contentEl.clientWidth + 100 &&
      !loading.value &&
      list.value.length < total.value
    ) {
      parmas.pageNo = parmas.pageNo + 1;
      init();
    }
    nextTick(() => {
      const { scrollLeft, clientWidth, scrollWidth } = scrollBox.value;
      if (scrollLeft > 100) {
        topShow.value = true;
      }
      if (scrollLeft < 100) {
        topShow.value = false;
      }
      const newScrollPercentage = Math.floor((scrollLeft / (scrollWidth - clientWidth)) * 100);
      percentage.value = newScrollPercentage == 99 ? 100 : newScrollPercentage;
    });
  }
};
const emitTop = () => {
  //点击回到列表最左侧
  scrollBox.value.scrollLeft = 0;
  percentage.value = 0;
  topShow.value = false;
};
const pathLink = (url?: string) => {
  if (!url) {
    return;
  }
  window.open(url, '_blank');
};
const blankHome = () => {
  store.menuId = null;
  router.push({ name: route.meta.loopType ? 'exhibitionHome' : 'templateedit' });
};
// import { publicUrls } from '@/utils/minxin';
// import { commonDataStore } from '@/store';
// const commonStore = commonDataStore();
// import { useRouter, useRoute } from 'vue-router';
// const router = useRouter();
// const route = useRoute();
// const blankHome=()=>{
//     router.push({name:route.meta.loopType?'exhibitionHome' : 'templateedit'})
// }
</script>

<style scoped lang="less">
.Cultural-box {
  width: 100%;
  // padding-bottom: 0px;
  padding: 30px 20px;
  background-size: contain !important;
  background-repeat: repeat !important;
  background-position: center !important;
}
.cultural-bg {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  padding: 115px 100px;
  background: url(https://static.jiyi.show/free/style4/publicStyle4Bg-1.png) no-repeat center/100% 100%;
}
.Cultural-heard {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 44px;
  .freeIcon {
    font-size: 52px;
    line-height: 32px;
    color: rgba(50, 43, 37, 1);
    margin-left: 0 !important;
    opacity: 0;
  }
  .backHome {
    cursor: pointer;
    width: 52px;
    height: 50px;
    margin-left: 0 !important;
  }
  .Cultural-heard-title {
    color: #5391a3;
    font-family: 'SourceHanSerifCN-Bold';
    font-size: 36px;
    line-height: 56px;
  }
  .percentage-text {
    display: flex;
    justify-content: flex-end;
    font-family: SourceHanSerifCN-Bold;
    font-size: 24px;
    line-height: 56px;
    text-align: center;
    color: rgba(50, 43, 37, 1);
    width: 120px;
  }
}
.right-scroll {
  display: flex;
  flex-wrap: wrap;
  // justify-content: center;
}
.right-scroll::-webkit-scrollbar {
  display: none;
}

.content-door {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 60%;
  position: absolute;
  bottom: -30px;
  .iconfonts {
    font-size: 26px;
    color: #83b0b3;
    margin-bottom: 4px;
    line-height: 32px;
  }
  span {
    font-family: PingFang SC;
    font-size: 16px;
    line-height: 32px;
    color: #83b0b3;
    margin-left: 20px;
    padding-bottom: 7px;
  }
}

.item-parent {
  width: calc(100% / 3 - 45px);
  // max-width: 310px;
  // height: 450px;
  aspect-ratio: 1/1.6;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  margin-bottom: 40px;
  margin-right: 60px;
  &:nth-child(3n) {
    margin-right: 0px !important;
  }
  .item {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    // height: 424px;
  }
  .item-img-box {
    width: 100%;
    flex: 1;
    background: url(https://static.jiyi.show/free/style4/culturalBg.png) no-repeat center/100% 100%;
    padding: 16px;
    .item-img {
      position: relative;
      z-index: 30;
      width: 100%;
      height: 100%;
    }
  }
  .item-name {
    width: 100%;
    font-family: 'MicrosoftYaHei';
    font-size: 18px;
    line-height: 36px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 18px;
    color: rgba(33, 35, 38, 1);
    text-indent: 0rem !important;
  }
  .item-btm {
    width: 100%;
    display: flex;
    align-items: baseline;
    .item-title2 {
      margin-right: 2px;
      color: #333;
      text-align: center;
      font-family: 'SourceHanSerifCN-Bold';
      font-size: 22px;
      line-height: 34px;
    }

    .item-title3 {
      color: rgba(51, 51, 51, 0.5);
      text-align: center;
      font-family: 'PingFangSC';
      font-size: 12px;
      line-height: 24px;
    }
    .item-title4 {
      width: 100%;
      color: #333;
      text-align: center;
      font-family: 'SourceHanSerifCN';
      font-size: 16px;
      line-height: 34px;
      text-align: left;
    }
  }
}

.solidBorder-child {
  width: 1px;
  height: 100%;
  background: rgba(131, 176, 179, 0.6);
  border-radius: 1px;
}
.is-null {
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 50%;
  left: 0;
  transform: translate(0, -50%);
  img {
    width: 190px;
    height: 190px;
  }
  span {
    font-family: PingFangSC, PingFang SC;
    font-size: 16px !important;
    color: #212326;
    line-height: 22px;
    opacity: 26%;
  }
}
.item-max {
  margin-right: 80px;
}
::v-deep .templatestyle1-scroll-box-tumb {
  align-items: center;
  justify-content: center;
  img {
    width: 24px;
    height: 24px;
  }
}
::v-deep .unit-exbit-null-remarks-info {
  width: 90%;
}
</style>